//
//  FileManagement.m
//  VideoExam
//
//  Created by apple on 2020/6/15.
//

#import "FileManagement.h"

@implementation FileManagement

+ (BOOL)create_document_folderName:(NSString *)folderName {
    NSString * docsdir = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
     NSString * shareFilePath = [docsdir stringByAppendingPathComponent:folderName];//将需要创建的串拼接到后面
     NSFileManager *fileManager = [NSFileManager defaultManager];
    if ([fileManager fileExistsAtPath:shareFilePath]) {//文件夹已经存在
        GDLog(@"文件夹已经存在");
        return YES;
    }
    
     BOOL isDir = NO;
     // fileExistsAtPath 判断一个文件或目录是否有效，isDirectory判断是否一个目录
     BOOL existed = [fileManager fileExistsAtPath:shareFilePath isDirectory:&isDir];
     if (!(isDir == YES && existed == YES) ) {//如果文件夹不存在
         [fileManager createDirectoryAtPath:shareFilePath withIntermediateDirectories:YES attributes:nil error:nil];
         GDLog(@"文件夹创建成功");

         return YES;
     }
    return NO;
}

/// 获取指定文件夹路径
/// @param fileFolderName 要获取的文件夹名称
+ (NSString *)get_Folder_specified_path_fileFolderName:(NSString *)fileFolderName {
    NSString * docsdir = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
    NSString * path = [docsdir stringByAppendingPathComponent:fileFolderName];
    GDLog(@"获取指定文件夹路径 %@",path);
    return path;
}

/// 删除指定文件夹
/// @param file_folder_name 文件夹名
+ (void)delete_file_folder_name:(NSString *)file_folder_name {
    NSString*share_video_file_name = [FileManagement get_Folder_specified_path_fileFolderName:share_video_file_folder_name];
    NSFileManager*fileManager = [NSFileManager defaultManager];
    if ([fileManager removeItemAtPath:share_video_file_name error:nil]) {
        NSLog(@"删除文件夹成功");
    } else {
         NSLog(@"删除文件夹失败==");
    }
}


#pragma mark  删除本地文件 无回调
///删除本地文件无回调
+ (void)delete_video_File_path:(NSString *)file_path {
  BOOL isSuccess = NO;
  NSError *error;
  NSFileManager *fileManager = [NSFileManager defaultManager];
  isSuccess = [fileManager removeItemAtPath:file_path error:&error];
  if (error) {
      NSLog(@"removeFile 失败：%@",[error localizedDescription]);
  }else{
      NSLog(@"removeFile 成功");
  }
}




@end
